{include file='public/header' /}
<style>
    .edui-dialog-image-body{
        height: 220px!important;
        overflow: hidden;
    }
    .edui-dialog-image .edui-image-wrapper{
        box-sizing: border-box;
        height: 100%;
    }
    .edui-tab-nav{
        height:43px;
    }
    .edui-dialog-image .edui-image-content {
        height: 200px!important;
    }
    .work{
        width:300px;
        margin-top: 10px
    }
    .work1{
        width:100px;
        margin-top: 10px
    }

</style>
<style>
    #demo2{
        display: flex;
        align-items: center;
    }
    #demo2 li .operate{ color: #000; display: none;}
    #demo2 li .close{position: absolute;top: 5px; right: 5px;cursor:pointer;}
    #demo2 li:hover .operate{ display: block;}
    .operate{
        position: absolute;
        right: 0;
        top: -9px;
        color: black;
        font-size: 34px;
        /* border: 1px solid red; */
        font-weight: bold;
    }
    .item_img{
        position: relative;margin-right: 10px;
    }
    .attribute{
        width: 100%;
        border: 1px solid #e6e6e6;
        margin-top:20px;
    }
    .atr{
        height: 50px;
        border: 1px solid #e6e6e6;
    }
    .ath{
        width: 100px; border-left: 1px solid #e6e6e6; border-right: 1px solid #e6e6e6;
    }
    .atd{
        display: flex;
        text-align: center;
        height: 38px;
        justify-content: center;
        align-items: center;
    }
    table input{
        text-align: center;
        border: none!important;
    }
    table td{
        border-right: 1px solid #e6e6e6;
        border-bottom: 1px solid #e6e6e6;
    }
    table td:last-child{
        border-right: none;
    }
</style>
<div class="layui-card">
    <div class="layui-card-header layuiadmin-card-header-auto">
        <h2>添加课程</h2>
    </div>
    <div class="layui-card-body">
        <form class="layui-form" action="{:__url('add')}" method="post" >


            <div class="layui-form-item">
                <label for="" class="layui-form-label">分类</label>
                <div class="layui-input-inline">
                    <select name="category_id" >
                        <option value="0"></option>
                        {foreach $data as $v}
                        <option value="{$v.id}" {if isset($row.category_id)&&$row.category_id==$v.id}selected{/if}>{$v.name}</option>
                        {if isset($v.childs) && !empty($v.childs)}
                        {foreach $v.childs as $vv}
                        <option value="{$vv.id}" {if isset($row.category_id)&&$row.category_id==$vv.id}selected{/if} >&nbsp;&nbsp;&nbsp;┗━━{$vv.name}</option>
                        {if isset($vv.childs) && !empty($vv.childs)}
                        {foreach $vv.childs as $vvv}
                        <option value="{$vvv.id}" {if isset($row.category_id)&&$row.category_id==$vvv.id}selected{/if} >
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;┗━━{$vvv.name}</option>
                        {/foreach}
                        {/if}
                        {/foreach}
                        {/if]
                        {/foreach}
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label for="" class="layui-form-label">课程标题</label>
                <div class="layui-input-block">
                    <input type="text" name="title" id="title" value="" lay-verify="required" placeholder="请输入课程标题" class="layui-input" >
                </div>
            </div>
            <!--<div class="layui-form-item">-->
                <!--<label for="" class="layui-form-label">名额数</label>-->
                <!--<div class="layui-input-block">-->
                    <!--<input type="number" name="total_number" value="" placeholder="请输入名额数" class="layui-input" >-->
                <!--</div>-->
            <!--</div>-->

            <div class="layui-form-item">
                <label for="" class="layui-form-label">材料费</label>
                <div class="layui-input-block">
                    <input type="number" name="materials" value="" placeholder="请输入材料费；0为无费用" class="layui-input" >
                </div>
            </div>
            <div class="layui-form-item">
                <label for="" class="layui-form-label">支付类型</label>
                <div class="layui-input-block">
                    <input type="radio" name="is_tuan"  lay-filter="raQT" value="0" title="非团购"  >
                    <input type="radio" name="is_tuan"  lay-filter="raQT" value="1" title="团购"  >
                </div>
            </div>

            <div class="layui-form-item">
                <label for="" class="layui-form-label">单价</label>
                <div class="layui-input-block">
                    <input type="number" name="price" value="" placeholder="请输入单价" class="layui-input" >
                </div>
            </div>
            <div class="layui-form-item">
                <label for="" class="layui-form-label">年龄段</label>
                <div class="layui-input-block">
                    <input type="text" name="age" value="" placeholder="请输入年龄段" class="layui-input" >
                </div>
            </div>
            <div class="layui-form-item">
                <label for="" class="layui-form-label">课时数</label>
                <div class="layui-input-block">
                    <input type="text" name="number" value="" placeholder="请输入课时数" class="layui-input" >
                </div>
            </div>
            <div class="layui-form-item">
                <label for="" class="layui-form-label">授课教师</label>
                <div class="layui-input-block">
                    <input type="text" name="teacher" value="" placeholder="请输入授课教师" class="layui-input" >
                </div>
            </div>
<span id="jq">
<div class="layui-form-item">
    <label for="" class="layui-form-label">团购价</label>
    <div class="layui-input-block">
        <input type="number" name="more_price" value="" placeholder="请输入团购价" class="layui-input" >
    </div>
</div>
<div class="layui-form-item">
    <label for="" class="layui-form-label">团人数</label>
    <div class="layui-input-block">
        <input type="number" name="num" value="" placeholder="请输入团人数" class="layui-input" >
    </div>
</div>
</span>


            <div class="layui-form-item layui-form-text" id="xxGroup">
                <label class="layui-form-label">上课时间：</label>
                <button  type="button" class="layui-btn icon-btn add"><i class="layui-icon">&#xe654;</i>新增</button>
                <div class="layui-input-block ">
                    <br/>
                    <div class="kecheng">

                    </div>

                </div>
            </div>

            <div class="layui-upload" style="margin: 20px 0;">
                <label class="layui-form-label">上课地址</label>

                <button type="button" class="layui-btn" id="attributes"><i class="layui-icon"></i>添加地址</button>
                <table class="attributes" style="margin-top: 10px;margin-left: 110px;">
                    <tr class="atr">
                        <th style="width: 600px;text-align:center">上课地址</th>
                        <th style="width: 150px;text-align:center">操作</th>
                    </tr>

                </table>
            </div>
            <div class="layui-upload" style="margin: 20px 0;">
                <label class="layui-form-label">科目</label>

                <button type="button" class="layui-btn" id="attributess"><i class="layui-icon"></i>添加科目</button>
                <table class="attributess" style="margin-top: 10px;margin-left: 110px;">
                    <tr class="atr">
                        <th style="width: 600px;text-align:center">科目名称</th>
                        <th style="width: 150px;text-align:center">操作</th>
                    </tr>

                </table>
            </div>
            <!-- 不同课程展示不同 -->
            <div class="layui-upload">
                <label class="layui-form-label">课程轮播图</label>
                <button type="button" class="layui-btn" id="test2">多图片上传</button>
                <span style="color: #FFB800">（图片尺寸：375px * 370px）</span>
                <blockquote class="layui-elem-quote layui-quote-nm " style="margin-top: 10px;margin-left: 110px;">
                    预览图：
                    <div class="layui-upload-list" id="demo2">


                    </div>
                </blockquote>
            </div>


            <div class="layui-form-item">
                <label for="" class="layui-form-label">主图</label>
                <div class="layui-input-block">
                    <div class="layui-upload">
                        <button type="button" class="layui-btn layui-btn-sm uploadPic"><i class="layui-icon">&#xe67c;</i>图片上传</button>
                        <div class="layui-upload-list" >
                            <ul class="layui-upload-box layui-clear">

                            </ul>
                            <input type="hidden" name="thumb" class="layui-upload-input" value="">
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <label for="" class="layui-form-label">视频 </label>
                <div class="layui-input-block">
                    <div class="layui-upload">
                        <button type="button" class="layui-btn layui-btn-sm uploadVideo"><i class="layui-icon">&#xe67c;</i>视频上传</button>
                        <div class="layui-upload-list" >
                            <ul class="layui-upload-box layui-clear">

                            </ul>
                            <input type="hidden" name="video" class="layui-upload-input" value="">
                        </div>
                    </div>
                </div>
            </div>


            <div class="layui-form-item">
                <label for="" class="layui-form-label">课程信息</label>
                <div class="layui-input-block">
                    <script id="container" name="content" type="text/plain" style="width: 1000px;">
        </script>
                </div>
            </div>



        </form>
    </div>
</div>
{include file='public/footer' /}
<script>
    layui.use(['layer','layedit'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;

        var layedit = layui.layedit;
        layedit.set({
            uploadImage:{
                url:'{:__url("admin/upload/upload")}'//接口url
                ,type:''//默认post
            }});

        var Index = layedit.build('qaContent'); // 建立编辑器

    })
</script>
<script>
    layui.use(['upload','layer','element','form','laydate'],function () {
        var $ = layui.jquery;
        var upload = layui.upload;
        var laydate = layui.laydate;
        var layer = layui.layer;
        var form = layui.form;
        //普通图片上传
        $(".uploadPic").each(function (index,elem) {
            upload.render({
                elem: $(elem)
                ,url: '{:__url("admin/upload/upload")}'
                ,multiple: false
                ,data:{"_token":"{{ csrf_token() }}"}
                ,done: function(res){
                    //如果上传失败
                    if(res.code == 0){
                        layer.msg(res.msg,{icon:1,time:1000},function () {
                            $(elem).parent('.layui-upload').find('.layui-upload-box').html('<li><img style="width:100px;height: 60px;" src="'+res.url+'" /></li>');
                            $(elem).parent('.layui-upload').find('.layui-upload-input').val(res.url);
                        })
                    }else {
                        layer.msg(res.msg,{icon:2,time:1000})
                    }
                }
            });
        })



        //多图片上传
        upload.render({
            elem: '#test2',
            url: '{:__url("admin/upload/upload")}'
            //上传接口
            ,
            data:{"_token":"{{ csrf_token() }}"},
            multiple: false,

            before:function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
//                    $('#demo2').append()
                });
            },
            done: function (res) {
                //上传完毕
                if (res.code == 0) {
                    //console.log(111)
                    $('#demo2').append('<li class="item_img"><div class="operate"></i><i  class="close layui-icon"></i></div><img src="' + res.url + '" class="layui-upload-img" width="60"><input type="hidden" name="image[]" value="' + res.url + '"></li>');
                } else {
                    layer.msg(res.msg,{icon:2,time:1000})
                }
            }
        });
//点击多图上传的X,删除当前的图片
        $("body").on("click",".close",function(){
            $(this).closest("li").remove();
        });
        $(".uploadVideo").each(function (index,elem) {
            upload.render({
                elem: $(elem)
                ,url: '{:__url("admin/upload/upload")}'
                ,multiple: false
                ,accept: 'video' //视频
                ,data:{"_token":"{{ csrf_token() }}",'file_type':2}
                ,done: function(res){
                    //如果上传失败
                    if(res.code == 0){
                        layer.msg(res.msg,{icon:1,time:1000},function () {
                            $(elem).parent('.layui-upload').find('.layui-upload-box').html('<li><video src='+res.url+' width="500" height="240" controls autobuffer></video></li>');

                            $(elem).parent('.layui-upload').find('.layui-upload-input').val(res.url);
                        })
                    }else {
                        layer.msg(res.msg,{icon:2,time:1000})
                    }
                }
            });
        })

        // 试题类型切换事件
        form.on('radio(raQT)', function (data) {

            changeQT(data.value);
        });

        function changeQT(value, sel) {

            if(value ==1){
                $('#jq').show();
                $('#jf').hide();
            }else{
                $('#jq').hide();
                $('#jf').show();
            }
        }

        //默认加载课程分类jf:钱；jq团
        $(function(){


            if($(':radio[name="is_tuan"]:checked').val() ==1){

                $('#jq').show();
                $('#jf').hide();
            } else{
                $('#jf').show();
                $('#jq').hide();
            }


        })

        /*添加一行*/
        $('.add').click(function(){
            var html='<div class="qa-xx-item ">'+
                    '<div class="layui-inline">'+
                    '<input type="text" name="work[]" placeholder="请输入时间段" class="layui-input layui-inline work" autocomplete="off" lay-verType="tips"  lay-verify="required" required/>'+

                    '</div>'+
                    '<div class="layui-inline">'+
                    '<input type="number" name="sort[]" value="" lay-verify="required|number" placeholder="请输入排序" class="layui-input layui-inline work1" >'+
                    '</div>'+

                    '<div class="layui-inline">'+
                    '<input type="number" name="numbers[]" value="" lay-verify="required|number" placeholder="请输入名额" class="layui-input layui-inline work1" > '+
                    '</div>'+

                    '<div class="layui-inline">'+
                    '<button  type="button" class="layui-btn icon-btn delone layui-inline work1"  ><i class="layui-icon"></i>删除</button>'+
                    '</div>'+
                '</div>';
            $('.kecheng').append(html);
        })
        //删除一行数据
        $("body").on("click",".delone",function(){

            $(this).parent().parent().remove()

        })

        //添加课时目录
        $('#attributes').click(function(){
            $(".attributes").append("<tr>"+"<td><input type='text' name='address[]'  lay-verify='required' maxlength='20' placeholder='上课地址,最多20个字' class='layui-input sl' ></td>" +
                    "<td style='text-align: center'><a href='javascript:;'class='layui-btn layui-btn-xs layui-btn-primary delete'  style='margin-right: 0;font-size:12px;'><span><i class='layui-icon'></i></span></a></td>"+"</tr>");

        })
        form.render('checkbox');
        $(document).on("click","span",function () {
            $(this).parents('tr').remove();
        })
        //添加课时目录
        $('#attributess').click(function(){
            $(".attributess").append("<tr>"+"<td><input type='text' name='subject[]'  lay-verify='required' maxlength='20' placeholder='科目,最多20个字' class='layui-input sl' ></td>" +
                    "<td style='text-align: center'><a href='javascript:;'class='layui-btn layui-btn-xs layui-btn-primary delete'  style='margin-right: 0;font-size:12px;'><span><i class='layui-icon'></i></span></a></td>"+"</tr>");

        })
        form.render('checkbox');
        $(document).on("click","span",function () {
            $(this).parents('tr').remove();
        })
        /*上传视频*/
        /* $("body").on("click",".uploadVideo",function(){

         upload.render({
         elem: $(this)
         ,url: '{{ route("api.upload") }}'
         ,multiple: false
         ,accept: 'video' //视频
         ,data:{"_token":"{{ csrf_token() }}"}
         ,done: function(res){
         //如果上传失败
         if(res.code == 0){
         layer.msg(res.msg,{icon:1},function () {

         $(elem).parent('.qa-xx-item').find('.layui-upload-input').val(res.url);
         })
         }else {
         layer.msg(res.msg,{icon:2})
         }
         }
         });


         });*/

    })
</script>
<link href="/baidu-editor/themes/default/css/umeditor.min.css" type="text/css" rel="stylesheet">
<script src="/baidu-editor/third-party/jquery.min.js"></script>
<!-- 配置文件 -->
<script type="text/javascript" src="/baidu-editor/umeditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="/baidu-editor/umeditor.min.js"></script>
<!-- 实例化编辑器 -->
<script type="text/javascript">
    var ue = UM.getEditor('container');

</script>